<?php namespace App\Models\Cxhshop;

use App\Models\Base\CxhshopBase;

class Shares extends CxhshopBase {

    protected $table = 'ims_cxh_stock_option';

    protected $fillable = [
            'member_id',
            'user_bank_id',
            'uch_type',
            'uch_money',
            'uch_credit2',
            'uch_credit4',
            'uch_credit5',
            'uch_poundage_money',
            'uch_real_money'
    ];

    public $timestamps = false;

    protected $dates = [];

    public static $rules = [
        // Validation rules
    ];

    /**
     * @param $memId
     * @return array
     * 获取股权列表
     */
    public function getList($memId){
        $query = self::query();
        $field = ['id','total_money','ctime','status'];
        $sharesList = $query -> where('member_id',$memId) -> orderBy('id','desc')->get($field)->toArray();
        return $sharesList;
    }

    /**
     * @param $sharesId 股权id
     * @param $memId 会员id
     * @return array
     * 获取股权详情
     */
    public function getDetailById($sharesId = 0,$memId = 0,$field = ['*']){
        $query = self::query();
        $shareDetail = $query -> where('id',$sharesId)->where('member_id',$memId)->first($field);
        if($shareDetail){
            $shareDetail = $shareDetail ->toArray();
        }else{
            $shareDetail = [];
        }
        return $shareDetail;
    }

    /**
     * 更新股权的相关字段
     * @param $money
     * @param $sharesId
     * @param $sharesInfo
     * @return int
     */
    public function saveSharesFields($sharesId,$shareSaveData){
        $query = self::query();
        $res = $query ->where('id',$sharesId) -> update($shareSaveData);
        return $res;
    }

}